package com.hmall.item.web;

import com.hmall.common.dto.Item;
import com.hmall.common.dto.ItemDoc;
import com.hmall.common.dto.PageDTO;
import com.hmall.common.dto.RequestParams;
import com.hmall.item.service.searchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
public class searchController {

    @Autowired
    searchService service;

    /**
     * 实现基本搜索功能
     * @param params
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> page(@RequestBody RequestParams params){
        return  service.seach(params);
    }

    /**
     * 搜索自动补全功能
     * @param prefx
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> GetSuggestion(@RequestParam("key") String prefx){
        return service.getSuggestions(prefx);
    }

    /**
     * .过滤项聚合功能
     * @param requestParams
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String> > getfilters (@RequestBody RequestParams  requestParams){
        return service.filters(requestParams);
    }

}
